/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.CompanyInfo;
/*     */ import com.newcrm.bean.Group;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CustomerManager;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ 
/*     */ public class ShowCustomerCategoryChangeChartData2 extends AbstractAction
/*     */ {
/*     */   public ShowCustomerCategoryChangeChartData2(AbstractHttpServlet servlet)
/*     */   {
/*  36 */     super(servlet);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  42 */     User user = super.getLoginUser(request);
/*  43 */     if ((!user.isAdmin) && (!user.isGroupAdmin))
/*     */     {
/*  45 */       super.showErrorMessage(response, "您没有查看该客户的权限");
/*  46 */       return;
/*     */     }
/*     */ 
/*  49 */     CompanyInfo company = super.getCompany(request);
/*     */ 
/*  51 */     int categoryId = Util.getURLIntParameter(request
/*  52 */       .getParameter("categoryId"));
/*     */ 
/*  54 */     String groupIds = "";
/*  55 */     if (!user.isAdmin) {
/*  56 */       Group group = company.getGroupById(user.groupId);
/*  57 */       if (group != null)
/*  58 */         groupIds = group.getAllIds();
/*     */       else {
/*  60 */         groupIds = String.valueOf(user.groupId);
/*     */       }
/*     */     }
/*     */ 
/*  64 */     CustomerManager manager = new CustomerManager();
/*     */ 
/*  66 */     Date startDate = Util.str2Date(request.getParameter("start"));
/*  67 */     Date endDate = Util.str2Date(request.getParameter("end"));
/*     */ 
/*  69 */     List result = manager
/*  70 */       .getCustomerCategoryChangeNumByGroupIds(user.companyId, 
/*  71 */       groupIds, categoryId, startDate, endDate);
/*     */ 
/*  73 */     if (result == null) {
/*  74 */       super.showErrorMessage(response, "");
/*  75 */       return;
/*     */     }
/*     */ 
/*  78 */     response.setContentType("text/html;charset=utf-8");
/*  79 */     PrintWriter out = response.getWriter();
/*  80 */     JSONObject jsonObject = new JSONObject();
/*     */ 
/*  82 */     List chars = new ArrayList();
/*  83 */      for (Object itemO : result) {
        Map item = (Map)itemO;
/*  84 */       int num = Util.str2Int(item.get("totalNum"));
/*  85 */       String permissionsId = (String)item.get("PermissionsId");
/*  86 */       String userName = company.getUserName(permissionsId);
/*  87 */       if (userName != null) {
/*  88 */         Map map = new HashMap();
/*  89 */         map.put("label", userName);
/*  90 */         map.put("value", Integer.valueOf(num));
/*  91 */         map.put("id", permissionsId);
/*  92 */         chars.add(map);
/*     */       }
/*     */     }
/*     */ 
/*  96 */     jsonObject.put("error", "0");
/*  97 */     jsonObject.put("chars", chars);
/*  98 */     out.println(jsonObject);
/*  99 */     out.flush();
/* 100 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.ShowCustomerCategoryChangeChartData2
 * JD-Core Version:    0.6.1
 */